package com.gm.wholesale.module.main.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.gm.wholesale.R;

public class MenuItemView extends LinearLayout {
    private ImageView menuIcon;
    private TextView menuNameTv;

    public MenuItemView(Context context) {
        super(context);
        initView(context,null);
    }

    public MenuItemView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView(context,attrs);
    }

    private void initView(Context context,AttributeSet attrs) {
        LayoutInflater.from(context).inflate(R.layout.view_menu_item,this);
        menuNameTv=findViewById(R.id.nameTv);
        menuIcon=findViewById(R.id.image);
        if (attrs != null) {
            final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.menuView);
            int imageId = a.getResourceId(R.styleable.menuView_menuIcon, 0);
            String text = a.getString(R.styleable.menuView_menuName);
            if (imageId>0){
                menuIcon.setImageResource(imageId);
                menuNameTv.setText(text);
            }
        }
    }

    public void showMenu(int icon,String name){
        if (icon>0){
            menuIcon.setImageResource(icon);
            menuNameTv.setText(name);
        }

    }

}
